<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>设计阶段</title>

<link rel="stylesheet" href="css/vivo.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" href="css/common.css">

<script src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script> 
<script type="text/javascript" src="js/form.js"></script>
</head>
<script type="text/javascript">
	  $(function(){
			//如果已经保存过了，则开启只读状态
			<c:if test="${not empty requestScope.designStage }">
				$("#designStage").find("input,textarea").attr("readonly",true);
				$("#designStage .Wdate").attr("disabled",true);
			</c:if>
			
			//鼠标悬浮提示
			toolTip();
	  });

  </script>
<body>
	<div style="padding:0px 10px">
		<form id="designStage" method="post" action=""  onsubmit="return false;">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h5 class="panel-title">设计阶段</h5>
				</div>
				<div class="panel-body">
					<table cellpadding="10" cellspacing="5" class="mytable">
						<tr>
							<td width="70">设计时间</td>
							<td width="260"><input name="designDate" id="designDate" value="<fmt:formatDate value="${requestScope.designStage.designDate }" pattern="yyyy-MM-dd" />"
								class="Wdate" readonly="readonly" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" /> <span style="color:red">*</span></td>
							<td width="70">设计名称</td>
							<td width="260"><input name="designName" class="toolTip" data-tip="${requestScope.designStage.designName }" id="designName" value="${requestScope.designStage.designName }" /><span style="color:red">*</span></td>
							<td width="70">设计单位</td>
							<td><input name="designUnit" id="designUnit" class="toolTip" data-tip="${requestScope.designStage.designUnit }" value="${requestScope.designStage.designUnit }" class="input_name" /></td>
						</tr>
					</table>
				</div>
			</div>
			<!-- 修改时添加变更说明 -->
			<div style="margin:10px;" hidden="hidden" id="changeRemark">
				变更说明<textarea rows="3" name="changeRemark"style="width:70%"></textarea><span style="color:red;">*</span>
			</div>
			<input type="hidden" id="entityId_id" name="id" value="${requestScope.designStage.id }"/>
			<div style="width:100%;text-align:center; padding-top:0px">
				<c:choose>
					<c:when test="${empty requestScope.designStage }">
						<button class="btn btn-danger radius my-btn"
							onclick="saveDesigns(0)" type="button">提交</button>
						<button class="btn btn-danger radius my-btn"
							onclick="saveDesigns(1)" type="button">保 存</button>
						<a class="btn btn-default radius" onClick="resetForms('designStage');">
							重置 </a>
						<br />
					</c:when>
					<c:otherwise>
						<shiro:hasPermission name="permission:edit">
							<button id="modifyBtn" class="btn btn-danger radius my-btn"
								onclick="saveDesigns(3)" type="button">启用编辑</button>
							<button class="btn btn-danger radius my-btn hidbtn"
								onclick="saveDesigns(2)" type="button">保存修改</button>
							<a class="btn btn-default radius hidbtn" onClick="resetForms('designStage');">
								重置 </a>	
						</shiro:hasPermission>
					</c:otherwise>
				</c:choose>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		function saveDesigns(opt) {
			if(opt==3){
				var approvalCount = ${approvalCount};
				if(approvalCount == 0 ){
					//解除锁定状态
					var index=layer.confirm('确定开启编辑状态？', {
					 	offset:'20%',
						shade:0
					}, function(){
					  //去除只读开启按钮编辑
					   $("#designStage #changeRemark").show();
					   $("#designStage").find("input,textarea").attr("readonly",false);
					   $("#designStage #modifyBtn").remove();
					   $("#designStage .hidbtn").removeClass("hidbtn");
					   $("#designStage .Wdate").attr("disabled",false);
					   layer.close(index);
					});
				}else{
					layer.msg("此条数据已提交过审批，不能重复提交");
				}
			}else {
				var i = layer.load(2);
				var designDate = $("#designDate").val();
				var designName = $("#designName").val();
				var designUnit = $("#designUnit").val();
				var fkPa = window.parent.$("#fkPa").val();
				var id = $("#designStage #entityId_id").val();
				var planId = parent.$("#entityId_planId").val();
				var changeRemark = $("#designStage textarea[name='changeRemark']").val();
				if(id != ""){
					if(changeRemark==""){
						layer.alert("变更说明不能为空");
						layer.close(i);
						return null;
					}
				}
				if (designDate == "") {
					layer.msg("设计时间不能为空");
					layer.close(i);
					return null;
				}else if(designName == ""){
					layer.msg("设计名称不能为空");
					layer.close(i);
					return null;
				}else if(!valLength(50,designUnit)){
					layer.msg("字数不能超过50字");
					$("input[name='designUnit']").focus();
					layer.close(i);
					return null;
				}
				var url = "project/approval/addDesign";
				jQuery.ajax({
					type : "post",
					async : true,
					url : url,
					dataType : "json",
					data : {
						id : id,
						fkProjectApproval : fkPa,
						designDate : designDate,
						designName : designName,
						designUnit : designUnit,
						opt :opt,
						planId :planId,
						changeRemark:changeRemark
					},
					success : function(responseText) {
						layer.close(i);
						if (responseText.success) {
							layer.alert("保存成功！", {
								offset:'20%',
								shade:[0.1,'#fff']
							}, function() {
								parent.location.reload();
							}); 
						} else {
							alert(responseText.msg, {icon : 7});
							layer.closeAll();
						}
					}
				});
			}
	
		}
	</script>
</body>
</html>

